package com.itheima.health.controller;

import com.itheima.health.dto.CheckGroupDTO;
import com.itheima.health.entity.QueryPageBean;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.CheckGroup;
import com.itheima.health.service.CheckGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
//
@RestController
@Api(tags = "检查组管理开发")
public class CheckGroupController {

    // springmvc  消息转化器   @ResponseBody  默认 全字段序列化

    @Reference
    private CheckGroupService checkGroupService;

    @GetMapping("checkgroup/findAll")
    @ApiOperation(value = "查询功能",notes = "查询所有的检查组列表信息")
    public Result findAll() {


        return new Result(checkGroupService.list());
    }


    @GetMapping("checkgroup/findCheckIteminfosByGroupId/{id}")
    @ApiOperation(value = "查询功能",notes = "根据检查组id查询对应检查项明细")
    public Result findCheckIteminfosByGroupId(@PathVariable("id") int id){
        return new Result(checkGroupService.findCheckIteminfosByGroupId(id));
    }

    @PostMapping("checkgroup/findPage")
    @ApiOperation(value = "分页查询功能",notes = "查询所有的检查组列表信息")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //    分页查询  条件  页码  记录数  条件
        //  集合 插件  PageResult对象
        return new Result(checkGroupService.findPage(queryPageBean));
    }
    @DeleteMapping("checkgroup/deleteCheckGroupitemById/{id}")
    @ApiOperation(value = "删除检查组", notes = "物理删除检查组")
    public Result deleteCheckGroupitemById(@PathVariable("id") int id) {
        CheckGroup checkGroup = new CheckGroup();
        checkGroup.setId(id);
        checkGroup.setIs_delete(1);
        boolean flag = checkGroupService.updateById(checkGroup);
        return new Result(flag);
    }

    @PostMapping("checkgroup/saveOrUpdate")
    @ApiOperation(value = "添加功能",notes = "添加检查组")
    public Result  saveOrUpdate(@RequestBody CheckGroupDTO checkGroupDTO ){
        return  new Result(checkGroupService.saveUpdate(checkGroupDTO));

    }
}
